package com.oig.sys.workflow.dao;

import com.oig.sys.workflow.entity.TbAutoOperation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author wuxl
 */
public interface ITbAutoOperationDao extends JpaRepository<TbAutoOperation, Integer> {

	@Query("from TbAutoOperation a where a.id=:id")
	TbAutoOperation getAutoOpById(@Param("id") Integer id);

	List<TbAutoOperation> findByAutoRuleId(Integer autoRuleId);

	@Query("select a.id from TbAutoOperation a where a.autoRuleId=:autoRuleId")
	List<Integer> findAllIdByRuleId(@Param("autoRuleId") Integer autoRuleId);

	@Query("select a.id from TbAutoOperation a where a.autoRuleId=:autoRuleId and a.id not in(:idList)")
	List<Integer> findAllDelId(@Param("autoRuleId") Integer autoRuleId, @Param("idList") List<Integer> idList);

	@Modifying
	@Query("delete from TbAutoOperation a where a.id in(:idList)")
	void deleteByIdList(@Param("idList") List<Integer> idList);

}
